<?php

class MyUrlManager extends CUrlManager{

	public function init()
	{
		$this->_initializeRules();
		parent::init();
	}
	
	private function _initializeRules()
	{
		if (installedModule('seo'))
		{
			$this->addRules(array( array('class' => 'application.modules.seo.components.SeoUrlRule') ));
			
//			foreach ($this->rules as $key=>$value)
//			{
//				unset($this->rules[$key]);
//				$key = '<language:('.implode('|', Languages::model()->getLanguageCodes()).')>/'.ltrim($key, '/');
//				$this->rules[$key] = $value;
//			}
		}
	}
	
    public function createUrl($route,$params=array(),$ampersand='&')
	{
//        if (!isset($params['language']))
//		{
//            if (Yii::app()->user->hasState('language'))
//			{
//                Yii::app()->language = Yii::app()->user->getState('language');
//			}
//            else if(isset(Yii::app()->request->cookies['language']))
//			{
//                Yii::app()->language = Yii::app()->request->cookies['language']->value;
//			}
//            $params['language']=Yii::app()->language;
//        }
 		return parent::createUrl($route, $params, $ampersand);
    }
}
